package com.mxx.common.security;

import com.mxx.common.utils.CharsetUtil;
import com.mxx.common.utils.Strings;

/**
 * @author: mxx
 * @date: 2022/3/21
 * @time: 10:15
 * @Description: 描述信息
 */
public class Constant {
    public enum CipherType {
        AES, DES, RSA, MAC;

    }

    public enum CipherBlock {
        CBC, ECB;
    }

    public enum CipherPadding {
        NO_PADDING("NoPadding"),
        PKCS5("PKCS5Padding"),
        PKCS7("PKCS7Padding"),
        OAEPWithSHA1("OAEPWithSHA-1AndMGF1Padding"),
        OAEPWithSHA256("OAEPWithSHA-246AndMGF1Padding"),
        ;
        private String val;

        CipherPadding(String val) {
            this.val = val;
        }

        public String getVal() {
            return val;
        }

        public byte[] complement(byte[] input) {
            if (this == CipherPadding.NO_PADDING) {
                int length = input.length;
                byte[] lastArr;
                //不足16倍数位，补充空
                if (length % 16 != 0) {
                    byte[] temp = new byte[16 - length % 16];
                    //用空格补位
                    byte[] fArr = Strings.toByte(" ");
                    for (int i = 0; i < temp.length; i++) {
                        temp[i] = fArr[0];
                    }
                    lastArr = new byte[length + temp.length];
                    for (int i = 0; i < length; i++) {
                        lastArr[i] = input[i];
                    }
                    for (int i = 0; i < temp.length; i++) {
                        lastArr[length + i] = temp[i];
                    }
                } else {
                    lastArr = input;
                }
                return lastArr;
            }
            return input;
        }
    }


    public enum Mac {
        MD5("HmacMD5"),
        SHA1("HmacSHA1"),
        SHA224("HmacSHA224"),
        SHA256("HmacSHA256"),
        SHA384("HmacSHA384"),
        SHA512("HmacSHA384");
        private String name;

        Mac(String name) {
            this.name = name;
        }
    }

    public enum Signature {
        NONE_RSA("NONEwithRSA"),
        MD2_RSA("MD2withRSA"),
        MD5_RSA("MD5withRSA"),
        SHA1_RSA("SHA1withRSA"),
        SHA224_RSA("SHA224withRSA"),
        SHA256_RSA("SHA256withRSA"),
        SHA384_RSA("SHA384withRSA"),
        SHA512_RSA("SHA512withRSA"),
        NONE_DSA("NONEwithDSA"),
        SHA1_DSA("SHA1withDSA"),
        SHA224_DSA("SHA224withDSA"),
        SHA256_DSA("SHA256withDSA"),
        NONE_ECDSA("NONEwithECDSA"),
        SHA1_ECDSA("SHA1withECDSA"),
        SHA224_ECDSA("SHA224withECDSA "),
        SHA256_ECDSA("SHA256withECDSA"),
        SHA384_ECDSA("SHA384withECDSA"),
        SHA512_ECDSA("SHA512withECDSA");
        private String name;

        Signature(String name) {
            this.name = name;
        }
    }

}
